﻿Imports System.Windows.Forms

Public Class EditCharacter
    Private ThisCharacter As New Character
    Private NewCharacter As Boolean = False

    Sub New(ByVal IsNewCharacter As Boolean, Optional ByRef EditCharacter As Character = Nothing)

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        NewCharacter = IsNewCharacter
        If Not EditCharacter Is Nothing Then
            ThisCharacter = EditCharacter
        End If
    End Sub
    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click, Button1.Click
        If NewCharacter Then
            MainForm.AllCharacters.Add(ThisCharacter)
        End If
        Me.DialogResult = System.Windows.Forms.DialogResult.Yes
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click, Button2.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub


    Private Sub EditCharacter_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.BodyNumericUpDown.DataBindings.Add("Value", ThisCharacter, "Body")
        Me.DCVNumericUpDown.DataBindings.Add("Value", ThisCharacter, "DCV")
        Me.DexterityNumericUpDown.DataBindings.Add("Value", ThisCharacter, "Dexterity")
        Me.EDNumericUpDown.DataBindings.Add("Value", ThisCharacter, "ED")
        Me.EgoNumericUpDown.DataBindings.Add("Value", ThisCharacter, "Ego")
        Me.EnduranceNumericUpDown.DataBindings.Add("Value", ThisCharacter, "Endurance")
        Me.MDCVNumericUpDown.DataBindings.Add("Value", ThisCharacter, "mDCV")
        Me.MDNumericUpDown.DataBindings.Add("Value", ThisCharacter, "MD")
        Me.MOCVNumericUpDown.DataBindings.Add("Value", ThisCharacter, "mOCV")
        Me.NameTextBox.DataBindings.Add("Text", ThisCharacter, "Name")
        Me.NPCCheckBox.DataBindings.Add("Checked", ThisCharacter, "NPC")
        Me.OCVNumericUpDown.DataBindings.Add("Value", ThisCharacter, "OCV")
        Me.PDNumericUpDown.DataBindings.Add("Value", ThisCharacter, "PD")
        Me.PowerDefenseNumericUpDown.DataBindings.Add("Value", ThisCharacter, "PowerDefense")
        Me.RecoveryNumericUpDown.DataBindings.Add("Value", ThisCharacter, "Recovery")
        Me.REDNumericUpDown.DataBindings.Add("Value", ThisCharacter, "rED")
        Me.RPDNumericUpDown.DataBindings.Add("Value", ThisCharacter, "rPD")
        Me.SpeedNumericUpDown.DataBindings.Add("Value", ThisCharacter, "Speed")
        Me.StunNumericUpDown.DataBindings.Add("Value", ThisCharacter, "Stun")
    End Sub

    Private Sub NumericUpDown_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles BodyNumericUpDown.Validating, DCVNumericUpDown.Validating, DexterityNumericUpDown.Validating, EDNumericUpDown.Validating, EnduranceNumericUpDown.Validating, EgoNumericUpDown.Validating, MDCVNumericUpDown.Validating, MDNumericUpDown.Validating, MOCVNumericUpDown.Validating, OCVNumericUpDown.Validating, PDNumericUpDown.Validating, PowerDefenseNumericUpDown.Validating, RecoveryNumericUpDown.Validating, REDNumericUpDown.Validating, RPDNumericUpDown.Validating, SpeedNumericUpDown.Validating, StunNumericUpDown.Validating
        Dim n As NumericUpDown = sender
        If n.Name.Contains("Speed") Then
            If n.Value > 12 Or n.Value < 1 Then
                e.Cancel = True
            End If
        End If
    End Sub

    Private Sub TextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles NameTextBox.Validating
        Dim t As TextBox = sender
        If String.IsNullOrEmpty(t.Text) Then
            e.Cancel = True
        End If
    End Sub

    Private Sub NameTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NameTextBox.TextChanged
        Me.ThisCharacter.Name = Me.NameTextBox.Text
    End Sub

    Private Sub NPCCheckBox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NPCCheckBox.CheckedChanged
        Me.ThisCharacter.NPC = Me.NPCCheckBox.Checked
    End Sub

    Private Sub BodyNumericUpDown_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BodyNumericUpDown.ValueChanged
        Me.ThisCharacter.Body = Me.BodyNumericUpDown.Value
    End Sub

    Private Sub StunNumericUpDown_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StunNumericUpDown.ValueChanged
        Me.ThisCharacter.Stun = Me.StunNumericUpDown.Value
    End Sub

    Private Sub SpeedNumericUpDown_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SpeedNumericUpDown.ValueChanged
        Me.ThisCharacter.Speed = Me.SpeedNumericUpDown.Value
    End Sub

    Private Sub DexterityNumericUpDown_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DexterityNumericUpDown.ValueChanged
        Me.ThisCharacter.Dexterity = Me.DexterityNumericUpDown.Value
    End Sub

    Private Sub RecoveryNumericUpDown_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RecoveryNumericUpDown.ValueChanged
        Me.ThisCharacter.Recovery = Me.RecoveryNumericUpDown.Value
    End Sub

    Private Sub EnduranceNumericUpDown_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EnduranceNumericUpDown.ValueChanged
        Me.ThisCharacter.Endurance = Me.EnduranceNumericUpDown.Value
    End Sub

    Private Sub OCVNumericUpDown_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OCVNumericUpDown.ValueChanged
        Me.ThisCharacter.OCV = Me.OCVNumericUpDown.Value
    End Sub

    Private Sub DCVNumericUpDown_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DCVNumericUpDown.ValueChanged
        Me.ThisCharacter.DCV = Me.DCVNumericUpDown.Value
    End Sub

    Private Sub EgoNumericUpDown_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EgoNumericUpDown.ValueChanged
        Me.ThisCharacter.Ego = Me.EgoNumericUpDown.Value
    End Sub

    Private Sub PDNumericUpDown_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PDNumericUpDown.ValueChanged
        Me.ThisCharacter.PD = Me.PDNumericUpDown.Value
    End Sub

    Private Sub EDNumericUpDown_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EDNumericUpDown.ValueChanged
        Me.ThisCharacter.ED = Me.EDNumericUpDown.Value
    End Sub

    Private Sub MDNumericUpDown_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MDNumericUpDown.ValueChanged
        Me.ThisCharacter.MD = Me.MDNumericUpDown.Value
    End Sub

    Private Sub RPDNumericUpDown_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RPDNumericUpDown.ValueChanged
        Me.ThisCharacter.rPD = Me.RPDNumericUpDown.Value
    End Sub

    Private Sub REDNumericUpDown_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles REDNumericUpDown.ValueChanged
        Me.ThisCharacter.rED = Me.REDNumericUpDown.Value
    End Sub

    Private Sub MOCVNumericUpDown_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MOCVNumericUpDown.ValueChanged
        Me.ThisCharacter.mOCV = Me.MOCVNumericUpDown.Value
    End Sub

    Private Sub PowerDefenseNumericUpDown_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PowerDefenseNumericUpDown.ValueChanged
        Me.ThisCharacter.PowerDefense = Me.PowerDefenseNumericUpDown.Value
    End Sub

    Private Sub MDCVNumericUpDown_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MDCVNumericUpDown.ValueChanged
        Me.ThisCharacter.mDCV = Me.MDCVNumericUpDown.Value
    End Sub
End Class
